package cn.tedu.hospitalqd.controller;

import cn.tedu.hospitalqd.pojo.dto.PaymentAddNewDTO;
import cn.tedu.hospitalqd.pojo.dto.PaymentUpdateDTO;
import cn.tedu.hospitalqd.pojo.vo.PaymentListItemVO;
import cn.tedu.hospitalqd.pojo.vo.PaymentStandardVO;
import cn.tedu.hospitalqd.service.PaymentService;
import cn.tedu.hospitalqd.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/payment")
@Api(tags = "08.项目缴费表管理模块")
@Validated
public class PaymentController {

    @Autowired
    private PaymentService paymentService;

    @PostMapping("/add-new")
    @ApiOperation("添加项目缴费表")
    @ApiOperationSupport(order = 100)
    public JsonResult addNew(@Valid PaymentAddNewDTO paymentAddNewDTO){
        log.debug("开始处理【添加项目缴费表】的请求，参数：{}",paymentAddNewDTO);
        paymentService.addNew(paymentAddNewDTO);
        return JsonResult.ok();
    }

    @PostMapping("/{id:[0-9]+}/delete")
    @ApiOperation("根据ID删除项目缴费表")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id",value = "项目缴费表ID",required = true,dataType = "long")
    })
    public JsonResult delete(@Range(min = 1,message = "删除项目缴费表失败，ID值无效")
                             @PathVariable Long id){
        log.debug("开始处理【根据ID删除项目缴费表】的请求，参数：{}",id);
        paymentService.delete(id);
        return JsonResult.ok();
    }

    @PostMapping("/{id:[0-9+]/update}")
    @ApiOperation("修改项目缴费表详情")
    @ApiOperationSupport(order = 310)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id",value = "类别ID",required = true,dataType = "long")
    })
    public JsonResult setEnable(@Range(min = 1,message = "修改项目缴费表详情失败，ID值无效！")
                                @PathVariable Long id, @Valid PaymentUpdateDTO paymentUpdateDTO){
        log.debug("开始处理【修改项目缴费表详情】的请求，参数：{}",paymentUpdateDTO);
        paymentService.updateInfoById(id,paymentUpdateDTO);
        return JsonResult.ok();
    }

    @PostMapping("/{id:[0-9]+}")
    @ApiOperation("根据ID查询项目缴费表详情")
    @ApiOperationSupport(order = 410)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id",value = "项目缴费表ID",required = true,dataType = "long")
    })
    public JsonResult getStandardById(@Range(min = 1,message = "获取相册详情失败，ID值无效！")
                                      @PathVariable Long id){
        log.debug("开始处理【根据ID查询项目缴费表详情】的请求，参数：{}",id);
        PaymentStandardVO queryResult = paymentService.getStandardById(id);
        return JsonResult.ok(queryResult);
    }

    @GetMapping("")
    @ApiOperation("查询项目缴费表列表")
    @ApiOperationSupport(order = 420)
    public JsonResult list(){
        log.debug("根据ID查询项目缴费表详情");
        List<PaymentListItemVO> list = paymentService.list();
        return JsonResult.ok(list);
    }
}
